package jannex.query;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class From<E> extends SelectClause<E> {

    private List<Table> tables = new ArrayList<>();

    From(Binding<E> binding, String tableName, String alias) {
        super(binding);
        tables.add(new Table(tableName).as(alias));
    }

    From(Binding<E> binding, Table... tables) {
        super(binding);
        this.tables.addAll(Arrays.asList(tables));
    }

    public From(String tableName, String alias) {
        this(new Table(tableName).as(alias));
    }

    public From(String tableName) {
        this(new Table(tableName));
    }

    public From(Table... tables) {
        this.tables.addAll(Arrays.asList(tables));
    }

    public From<E> as(String alias) {
        tables.get(tables.size()-1).as(alias);
        return this;
    }

    public From<E> and(String tableName) {
        tables.add(new Table(tableName));
        return this;
    }

}
